<?php include '../../checkPCandVPC.php'; ?>
<?php include 'top.html'; ?>
<?php include 'notifier.php'; ?>
<?php include '../../authorization_check.php'; ?>

<?php

require_once '../../commonutils/util/PageTemplate.php';
require_once '../../commonutils/db/DBConnectionManager.php';


//global variables
$totalPayment = 0;
$count = 0;
$dcount = 0;
$count2 = 0;
$dcount2 = 0;
$totalCredit = 0;
$totalPayment = 0;
$EXPENSE = 0;
$INCOME = 0;
$totalInstructorPayment = 0;
$totalPersonnelPayment = 0;
$depSC;
$depSC2;
$bosrow = 0;
$bosrow2 = 0;
//$dep; 

function addJavaScripts($webPage){
	$javaScript = '

		function checkAddNewCirculationMoney(){
			
			var CirculationMoney = window.document.listIONBudgetForm.textCirculationMoney;
				
		   	if(CirculationMoney.value == ""){
		   		alert("CirculationMoney can not be empty");
		   		CirculationMoney.focus();
		   		return false;
		   	}
		   	
    		return true;
		}
		
		';
	$webPage->addJavaScriptContent($javaScript);
	$webPage->addCommonJavaScripts();
}


function listIONBudgetForm($webPage){
$webPage->addContent("<form name='IONBudgetForm' method='post' action=''>");				
}

//FIND THE NUMBER OF RECORDS AND NUMBER OF DIFFERENT DEPARTMENTS GLOBALY

$result = DBConnectionManager::query("SELECT DISTINCT
  student.studentID,
  student.programCode,
  studentpayment.studentID,
  studentpayment.amount
FROM
  student,
  studentpayment
WHERE
  student.studentID = studentpayment.studentID AND 
  student.programCode = '9040'
");

		while($row = mysql_fetch_assoc($result)){
			$totalPayment += $row['amount'];
		}
		
$result2 = DBConnectionManager::query("SELECT 
  course.credit
FROM
  course,
  enrollment,
  section
WHERE
  course.courseCode LIKE '9040%' AND 
  enrollment.semesterID = section.semesterID AND 
  enrollment.sectionID = section.sectionID AND 
  section.courseCode = course.courseCode
");

		while($row2 = mysql_fetch_assoc($result2)){
			$totalCredit += $row2['credit'];
		}
		//echo "credit:"$row2['credit'];
		
$result3 = DBConnectionManager::query("select *
from Instructor i, InstructorPayment ip
where i.instructorID=ip.instructorID and
i.programCode = '9040'
");

		while($row3 = mysql_fetch_assoc($result3)){
			$totalInstructorPayment += ( $row3['paymentperhour'] * $row3['lecturehourperweek'] * $row3['numberofweeks'] ) + $row3['finalexampayment'];
		}
		//echo "credit:"$row2['credit'];
		
$result4 = DBConnectionManager::query("select * 
from Personnel p, PersonnelPayment pp 
where	p.personnelID=pp.personnelID and 
pp.programCode = '9040'
");

		while($row4 = mysql_fetch_assoc($result4)){
			$totalPersonnelPayment += $row4['weeklyHours'] * $row4['feePerWeek'] * $row4['week'];
		}	

function listIONBudgetIncome($webPage){
	
	global $count, $dcount, $dep, $depN, $totalCredit, $totalPayment,$bosrow, $depSC, $INCOME ;
	//$totalCredit = 0;
	$totalPayment = 0;
	//echo "loopNo:"."$loopNo";
	
	//echo "sonraki dep: ";
	//echo "$dep[0]";
		
	$webPage->addContent("<form name='listIONBudgetForm' method='post'>");
	$webPage->addContent("<table align = 'center' border=1 name='listIONBudgetTable'>");
	$webPage->addContent("<tr>");
	$webPage->addContent("<tr></td><th align= left><b>Total Number of Student Credit          </b></th><th>$totalCredit</th>");
	$webPage->addContent("<tr></td><th align= left><b>Payment per Credit (YTL)           </b></th><th>300</th>");
	$totalPayment = $totalCredit * 300;
	$webPage->addContent("<tr></td><th align= left>Total Semester Income (YTL) (Total Credit x Payment per Credit)        </th><th>$totalPayment</th>");
	$webPage->addContent("</tr>");
	$webPage->addContent("</tr>");
	//echo "dep[loopNo]: ";
	//echo "$dep[$loopNo]";	
	
	
	$webPage->addContent("</table>");
	$webPage->addContent("<table align = 'center'><tr>");
	$webPage->addContent("<td>");
	$webPage->addContent("</td>");
	$webPage->addContent("<td>");
	$webPage->addContent("</td>");
	$webPage->addContent("</tr></table></form>");
	$INCOME += $totalPayment;
	
}

function listIONBudgetExpense($webPage){
	
	global $count, $dcount, $dep, $depN, $totalCredit,$totalPersonnelPayment, $totalInstructorPayment,$totalExpense,$bosrow, $depSC,$EXPENSE ;
	//$totalCredit = 0;
	//echo "loopNo:"."$loopNo";
	
	//echo "sonraki dep: ";
	//echo "$dep[0]";
		
	$webPage->addContent("<form name='listIONBudgetForm' method='post'>");
	$webPage->addContent("<table align = 'center' border=1 name='listIONBudgetTable'>");
	$webPage->addContent("<tr>");
	$webPage->addContent("<tr></td><th align= left><b>Total Semester Expense of Academic Staff (YTL)      </b></th><th>$totalInstructorPayment</th>");
	$webPage->addContent("<tr></td><th align= left><b>Total Semester Expense of Personnel(YTL)           </b></th><th>$totalPersonnelPayment</th>");
	$totalExpense = $totalInstructorPayment + $totalPersonnelPayment;
	$webPage->addContent("<tr></td><th align= left>Total Semester Expense (YTL) (Total Academic Staff Expense x Total Academic Personnel Expense)        </th><th>$totalExpense</th>");
	//echo "dep[loopNo]: ";
	//echo "$dep[$loopNo]";	
	
	$webPage->addContent("</table>");
	$webPage->addContent("<table align = 'center'><tr>");
	$webPage->addContent("<td>");
	$webPage->addContent("</td>");
	$webPage->addContent("<td>");
	$webPage->addContent("</td>");
	$webPage->addContent("</tr></table></form>");
	$EXPENSE += $totalExpense;
	
}

function listIONBudgetDetails($webPage){
	
	global $count, $dcount, $dep, $depN, $totalCredit,$totalPersonnelPayment, $totalInstructorPayment,$totalExpense,$bosrow,$totalPayment, $depSC , $INCOME;
	//$totalCredit = 0;
	//echo "loopNo:"."$loopNo";
	
	//echo "sonraki dep: ";
	//echo "$dep[0]";
	
	//$CirculatingMoney = 1000000;
		
	$webPage->addContent("<form name='listIONBudgetForm' method='post'>");
	$webPage->addContent("<table align = 'center' border=1 name='listIONBudgetTable'>");
	$webPage->addContent("<tr>");
	$webPage->addContent("<tr><td colspan = 1/></td><th align= left><u>INCOME</u></th>");
	$webPage->addContent("<tr></td><th align= left><b>Circulating Money from the Previous Semester (YTL)     </b></th>");
	$CirculationMoney = $_POST['textCirculationMoney'];
	$webPage->addContent("<td align=left><input type=text name=textCirculationMoney onKeyPress='numericalOnly()'</td>");
	$webPage->addContent("<tr></td><th align= left><b>Total Semester Income (YTL)           </b></th><th>$totalPayment</th>");
	//$totalExpense = $totalInstructorPayment + $totalPersonnelPayment;
	//$webPage->addContent("<tr></td><th align= left>Total Semester Expense (YTL) (Total Academic Staff Expense x Total Academic Personnel Expense)        </th><th>$totalExpense</th>");
	//echo "dep[loopNo]: ";
	//echo "$dep[$loopNo]";	
	
	$webPage->addContent("</table>");
	$webPage->addContent("<table align = 'center'><tr>");
	$webPage->addContent("<td>");
	$webPage->addContent("</td>");
	$webPage->addContent("<td>");
	$webPage->addContent("</td>");
	$webPage->addContent("</tr></table></form>");
	$INCOME += $totalPayment + $CirculationMoney;
}

//************************************************************************//
//************************************************************************//
//*******************NON ION STUDENTS ************************************//
//************************************************************************//
//************************************************************************//
//************************************************************************//

  function listNonProgStudentsForm($webPage){
  $webPage->addContent("<form name='listNonProgStudentsforIONForm' method='post' action=''>");				
  }

  //FIND THE NUMBER OF RECORDS AND NUMBER OF DIFFERENT DEPARTMENTS GLOBALY



  $resultNON = DBConnectionManager::query("SELECT DISTINCT
    enrollment.studentID,
    enrollment.semesterID,
    enrollment.sectionID,
    course.courseName,
    course.courseCode,
    student.lastName,
    student.firstName,
    section.semesterID,
    section.sectionID,
    section.courseCode,
    student.programCode,
    course.credit,
    program.longName,
    program.programCode,
    student.studentID
  FROM
    enrollment,
    course,
    student,
    section,
    program
  WHERE
    (enrollment.studentID = student.studentID) AND
    (enrollment.semesterID = section.semesterID) AND
    (enrollment.sectionID = section.sectionID) AND
    (section.courseCode = course.courseCode) AND
    (student.programCode = program.programCode) AND
    (student.programCode <> '9040') AND
    (section.courseCode LIKE '9040%')
  GROUP BY
    enrollment.studentID,
    enrollment.semesterID,
    enrollment.sectionID,
    section.courseCode
  ORDER BY
    student.programCode
  ");
		
		//-----------------------------------------------------------
		//ERRRRRRRRRRRRRRRRRRRROOOOOOOOOOOOOOOOOOOOOOR
		//print ("Error: (" . mysql_errno() . ") " . mysql_error());
    //-----------------------------------------------------------
    
    //$row = mysql_fetch_assoc($result);
      $dep2[$dcount2] = 'xx';
      
      //$names = $row['firstName'];
      //echo "$names";
      $depSC2[$dcount2] = 1;
      
      
      while($rowNON = mysql_fetch_assoc($resultNON)){
      //$names2 = $row['firstName'];
      if( $rowNON['programCode'] != $dep2[$dcount2] ){
      		$depN2[$dcount2] = $rowNON['longName'];
      		$dcount2++;
            $depSC2[$dcount2] = 0;
            //echo "depSC[".$dcount."]=".$depSC[$dcount]."<br>";
            $dep2[$dcount2] = $rowNON['programCode'];
            $depN2[$dcount2] = $rowNON['longName'];
            
            }			
        $depSC2[$dcount2]++;
        //echo "depSC[".$dcount."]=".$depSC[$dcount]."<br>";
      }
    /*echo "onceki dep: ";
    echo "$dep[0]";
    echo "ustteki count: ";
    echo "$count"+1;
    echo "ustteki dcount: ";
    echo "$dcount"+1;*/

function listNonIONStudents($webPage, $loopNo){
    
    global $count2, $dcount2, $dep2, $depN2, $totalCredit2, $totalPayment2,$bosrow2, $depSC2,$INCOME ;
    $totalCredit2 = 0;
    $totalPayment2 = 0;
    //echo "loopNo:"."$loopNo";
    
    //echo "sonraki dep: ";
    //echo "$dep[0]";
      
    $webPage->addContent("<form name='listNonProgStudentsforIONForm' method='post'>");
    $webPage->addContent("<table align = 'center' border=1 name='listNonProgStudentsforIONTable'>");
    $webPage->addContent("<tr>");
      /*$webPage->addContent("<th>Student ID</th>");
      $webPage->addContent("<th>Name</th>");
      $webPage->addContent("<th>Surname</th>");
      $webPage->addContent("<th>Department</th>");
      $webPage->addContent("<th>Course Code</th>");
      $webPage->addContent("<th>Course Name</th>");
      $webPage->addContent("<th>Course Credit</th>");
      $webPage->addContent("<th>Total Payment (YTL)</th>");*/
    $webPage->addContent("</tr>");
    
    //echo "dep[loopNo]: ";
    //echo "$dep[$loopNo]";
    
      $resultNON = DBConnectionManager::query("SELECT DISTINCT
    enrollment.studentID,
    enrollment.semesterID,
    enrollment.sectionID,
    course.courseName,
    course.courseCode,
    student.lastName,
    student.firstName,
    section.semesterID,
    section.sectionID,
    section.courseCode,
    student.programCode,
    course.credit,
    program.longName,
    program.programCode,
    student.studentID
  FROM
    enrollment,
    course,
    student,
    section,
    program
  WHERE
    (enrollment.studentID = student.studentID) AND
    (enrollment.semesterID = section.semesterID) AND
    (enrollment.sectionID = section.sectionID) AND
    (student.programCode = program.programCode) AND
    (section.courseCode = course.courseCode) AND
    (student.programCode <> '9040') AND
    (section.courseCode LIKE '9040%')
  GROUP BY
    enrollment.studentID,
    enrollment.semesterID,
    enrollment.sectionID,
    section.courseCode
  ORDER BY
    student.programCode
  "); 
    //echo "for oncesi: ";
    //echo "$count"+1;
    $bosrow2 = 0;
    //echo "loopNo:".$loopNo;
    for($l2=0; $l2 < $loopNo ; $l2++){
    //echo "xxxxx".$depSC[$l]."<br>";
    $bosrow2 = $bosrow2 + $depSC2[$l2];
    
    //for($k =0; $k <= $depSC[$l]; $k++){
    //  $bosrow ++;
    //  echo $k;
    //  echo $bosrow;
    //}
    }
    //echo "bosRow Sayisi for:".$loopNo.": ".$bosrow."<br>";
    $i = 0;
    $j = 0;
    while($rowNON = mysql_fetch_assoc($resultNON))
    {
      if($i < $bosrow2)
        {
          //echo "i:".$i."<br>";
        }
        
        else{
        if($j < $depSC2[$loopNo]){
        $studentID = $rowNON['studentID'];
        //echo "$studentID"." "; 
        $firstName = $rowNON['firstName']; 
        //echo "$firstName"." "; 
        $lastName = $rowNON['lastName']; 
        //echo "$lastName"." "; 
        $department = $rowNON['longName'];
        //echo "$department"." "; 
        $courseCode = $rowNON['courseCode'];
        //echo "$courseCode"." "; 
        $courseName = $rowNON['courseName'];
        //echo "$courseName"." "; 
        $credit = $rowNON['credit'];
        //echo "$credit"." "; 
        $totalCredit2 +=$credit;
        //echo "$totalCredit"." "; 
        $totalStudentPayment2 = 300 * $credit;
        //echo "$totalStudentPayment"." "; 
        $totalPayment2 += $totalStudentPayment2;
        //echo "$totalPayment"."<br>"; 
        $webPage->addContent("<tr>");
          /*$webPage->addContent("<td>$studentID</td>");
          $webPage->addContent("<td>$firstName</td>");
          $webPage->addContent("<td>$lastName</td>");
          $webPage->addContent("<td>$department</td>");
          $webPage->addContent("<td>$courseCode</td>");
          $webPage->addContent("<td>$courseName</td>");
          $webPage->addContent("<td align = 'center'>$credit</td>");
          $webPage->addContent("<td align = 'center'>$totalStudentPayment2</td>");*/
          //$webPage->addContent("<td>$totalPaymentForACourse</td>");	
        $webPage->addContent("</tr>");
        //$count++;
      
    
    
    
    $j ++;
    }
    else
    {
    break;
    }
    
    }
    $i ++;
  }
  
  
  $webPage->addContent("<tr><td colspan = 6/></td><th align= left>Total Income from This Department (YTL) </th><th align=center>$totalPayment2</th>");
    $webPage->addContent("<tr><td colspan = 6/></td><th align= left>Total Credit Taken from This Department Students</th><th align=center>$totalCredit2</th>");
    $webPage->addContent("</tr>");
    $webPage->addContent("</table>");
    $webPage->addContent("<table align = 'center'><tr>");
    $webPage->addContent("<td>");
    $webPage->addContent("</td>");
    $webPage->addContent("<td>");
    $webPage->addContent("</td>");
    $webPage->addContent("</tr></table></form>");
    $INCOME += $totalPayment2;
  }

function listIONExpenseBudgetDetails($webPage){
	
	global $count, $dcount, $dep, $depN, $totalCredit,$totalPersonnelPayment, $totalInstructorPayment,$totalExpense,$bosrow,$totalPayment, $depSC, $EXPENSE ;
	//$totalCredit = 0;
	//echo "loopNo:"."$loopNo";
	
	//echo "sonraki dep: ";
	//echo "$dep[0]";
	
	$BAP = $totalPayment * 0.3; 
	$RS = $totalPayment * 0.03; 
	$webPage->addContent("<form name='listIONBudgetForm' method='post'>");
	$webPage->addContent("<table align = 'center' border=1 name='listIONBudgetTable'>");
	$webPage->addContent("<tr>");
	$webPage->addContent("<tr><td colspan = 1/></td><th align= left><u>EXPENSE</u></th>");
	$webPage->addContent("<tr></td><th align= left><b>B.A.P (%30)     </b></th><th>$BAP</th>");
	$webPage->addContent("<tr></td><th align= left><b>Rectorship Share (%3)         </b></th><th>$RS</th>");
	$totalExpense = $totalInstructorPayment + $totalPersonnelPayment;
	$webPage->addContent("<tr></td><th align= left>Total Semester Salary (YTL) (Total Academic Staff Expense x Total Academic Personnel Expense)        </th><th>$totalExpense</th>");
	//echo "dep[loopNo]: ";
	//echo "$dep[$loopNo]";	
	
	$webPage->addContent("</table>");
	$webPage->addContent("<table align = 'center'><tr>");
	$webPage->addContent("<td>");
	$webPage->addContent("</td>");
	$webPage->addContent("<td>");
	$webPage->addContent("</td>");
	$webPage->addContent("</tr></table></form>");
	$EXPENSE += $BAP + $RS;
	
}

//************************************************************************//
//************************************************************************//
//*************************ION STUDENTS***********************************//
//************************************************************************//
//************************************************************************//
//************************************************************************//
  function listIONStudTakingNonProgCourseForm($webPage){
  $webPage->addContent("<form name='listIONStudTakingNonProgCoursesForm' method='post' action=''>");				
  }

  //FIND THE NUMBER OF RECORDS AND NUMBER OF DIFFERENT DEPARTMENTS GLOBALY



  $result = DBConnectionManager::query("SELECT DISTINCT
  enrollment.studentID,
  enrollment.semesterID,
  enrollment.sectionID,
  course.courseName,
  course.courseCode,
  student.lastName,
  student.firstName,
  section.semesterID,
  section.sectionID,
  section.courseCode,
  student.programCode,
  course.credit,
  program.longName,
  student.studentID,
  course.programCode
FROM
  enrollment,
  course,
  student,
  section,
  program
WHERE
  enrollment.studentID = student.studentID AND
  enrollment.semesterID = section.semesterID AND
  enrollment.sectionID = section.sectionID AND
  section.courseCode = course.courseCode AND
  student.programCode = program.programCode AND
  student.programCode LIKE '9040' AND
  section.courseCode <> '9040%'
GROUP BY
  enrollment.studentID,
  enrollment.semesterID,
  enrollment.sectionID,
  section.courseCode
ORDER BY
  course.programCode
  ");
		
		//-----------------------------------------------------------
		//ERRRRRRRRRRRRRRRRRRRROOOOOOOOOOOOOOOOOOOOOOR
		//print ("Error: (" . mysql_errno() . ") " . mysql_error());
    //-----------------------------------------------------------
    
    //$row = mysql_fetch_assoc($result);
      $dep[$dcount] = 'xx';
      
      //$names = $row['firstName'];
      //echo "$names";
      $depSC[$dcount] = 1;
      
      
      
      while($row = mysql_fetch_assoc($result)){
      //$names2 = $row['firstName'];
      $code = $row['programCode'];
      $lName= $row['longName'];
      //echo "code:".$code."<br>";
      //echo "LongName:".$lName."<br>";
      
      if( $row['programCode'] != $dep[$dcount] ){
      //echo "girdim"."<br>";
          $depNo[$dcount] = $code = $row['programCode'];
      		$depN[$dcount] = $row['longName'];
      		$dcount++;
            $depSC[$dcount] = 0;
            //echo "depSC[".$dcount."]=".$depSC[$dcount]."<br>";
            $dep[$dcount] = $row['programCode'];
            $depN[$dcount] = $row['longName'];
            
            }			
        $depSC[$dcount]++;
        
        //echo "depSC[".$dcount."]=".$depSC[$dcount]."<br>";
      }

  function listIONStudents($webPage, $loopNo){
    
    global $count, $dcount, $dep, $depN, $totalCredit, $totalPayment,$bosrow, $depSC,$EXPENSE ;
    $totalCredit = 0;
    $totalPayment = 0;
    //echo "loopNoUst:"."$loopNo"."<br>";
    
    //echo "sonraki dep: ";
    //echo "$dep[0]";
      
    $webPage->addContent("<form name='listIONStudTakingNonProgCourseForm' method='post'>");
    $webPage->addContent("<table align = 'center' border=1 name='listIONStudTakingNonProgCourseTable'>");
    $webPage->addContent("<tr>");
      /*$webPage->addContent("<th>Student ID</th>");
      $webPage->addContent("<th>Name</th>");
      $webPage->addContent("<th>Surname</th>");
      $webPage->addContent("<th>Department</th>");
      $webPage->addContent("<th>Course Code</th>");
      $webPage->addContent("<th>Course Name</th>");
      $webPage->addContent("<th>Course Credit</th>");
      $webPage->addContent("<th>Total Payment (YTL)</th>");*/
    $webPage->addContent("</tr>");
    
    //echo "dep[loopNo]: ";
    //echo "$dep[$loopNo]";
    
      $result = DBConnectionManager::query("SELECT DISTINCT
  enrollment.studentID,
  enrollment.semesterID,
  enrollment.sectionID,
  course.courseName,
  course.courseCode,
  student.lastName,
  student.firstName,
  section.semesterID,
  section.sectionID,
  section.courseCode,
  student.programCode,
  course.credit,
  program.longName,
  student.studentID,
  course.programCode
FROM
  enrollment,
  course,
  student,
  section,
  program
WHERE
  enrollment.studentID = student.studentID AND
  enrollment.semesterID = section.semesterID AND
  enrollment.sectionID = section.sectionID AND
  section.courseCode = course.courseCode AND
  student.programCode = program.programCode AND
  student.programCode LIKE '9040' AND
  section.courseCode <> '9040%'
GROUP BY
  enrollment.studentID,
  enrollment.semesterID,
  enrollment.sectionID,
  section.courseCode
ORDER BY
  course.programCode
  "); 
    //echo "for oncesi: ";
    //echo "$count"+1;
    $bosrow = 0;
    //echo "bosrow1:".$bosrow."<br>";
    
    //echo "loopNo:".$loopNo."<br>";
    
    
    //echo "loopNo:".$loopNo;
    for($l=0; $l < $loopNo ; $l++){
    //echo "depSC[l]".$depSC[$l]."<br>";
    $bosrow = $bosrow + $depSC[$l];
    
    
    
    //for($k =0; $k <= $depSC[$l]; $k++){
    //  $bosrow ++;
    //  echo $k;
    //echo "bosrow2:".$bosrow."<br>";
    //}
    }
    //echo "bosRow Sayisi for:".$loopNo.": ".$bosrow."<br>";
    $i = 0;
    $j = 0;
    while($row = mysql_fetch_assoc($result))
    {
      if($i <= $bosrow)
        {
          //echo "i:".$i."<br>";
        }
        
        else{
        //echo "depSC[loopNo]:".$depSC[$loopNo]."<br>";
        //echo "j:".$j."<br>";
        if($j <= $depSC[$loopNo]){
        $studentID = $row['studentID'];
        //echo "$studentID"." "; 
        $firstName = $row['firstName']; 
        //echo "$firstName"." "; 
        $lastName = $row['lastName']; 
        //echo "$lastName"." "; 
        $department = $row['longName'];
        //echo "$department"." "; 
        $courseCode = $row['courseCode'];
        //echo "$courseCode"." "; 
        $courseName = $row['courseName'];
        //echo "$courseName"." "; 
        $credit = $row['credit'];
        //echo "$credit"." "; 
        $totalCredit +=$credit;
        //echo "$totalCredit"." "; 
        $totalStudentPayment = 300 * $credit;
        //echo "$totalStudentPayment"." "; 
        $totalPayment += $totalStudentPayment;
        //echo "$totalPayment"."<br>"; 
        $webPage->addContent("<tr>");
          /*$webPage->addContent("<td>$studentID</td>");
          $webPage->addContent("<td>$firstName</td>");
          $webPage->addContent("<td>$lastName</td>");
          $webPage->addContent("<td>$department</td>");
          $webPage->addContent("<td>$courseCode</td>");
          $webPage->addContent("<td>$courseName</td>");
          $webPage->addContent("<td align = 'center'>$credit</td>");
          $webPage->addContent("<td align = 'center'>$totalStudentPayment</td>");*/
          //$webPage->addContent("<td>$totalPaymentForACourse</td>");	
        $webPage->addContent("</tr>");
        //$count++;
      
    
    
    
    $j ++;
    }
    else
    {
    break;
    }
    
    }
    $i ++;
  }
  
  
  $webPage->addContent("<tr><td colspan = 6/></td><th align= left> Total Payment to This Department (YTL) </th><th align=center>$totalPayment</th>");
    $webPage->addContent("<tr><td colspan = 6/></td><th align= left> Total Credit Taken from ION Students from This Department </th><th align=center>$totalCredit</th>");
    $webPage->addContent("</tr>");
    $webPage->addContent("</table>");
    $webPage->addContent("<table align = 'center'><tr>");
    $webPage->addContent("<td>");
    $webPage->addContent("</td>");
    $webPage->addContent("<td>");
    $webPage->addContent("</td>");
    $webPage->addContent("</tr></table></form>");
    
    $EXPENSE += $totalPayment;
  }


function listIONBudgetTotals($webPage){
	
	global $count, $dcount, $dep, $depN, $totalCredit,$totalPersonnelPayment, $totalInstructorPayment,$totalExpense,$bosrow,$totalPayment, $depSC, $INCOME,$EXPENSE ;
	//$totalCredit = 0;
	//echo "loopNo:"."$loopNo";
	
	//echo "sonraki dep: ";
	//echo "$dep[0]";
	
	//$BAP = $totalPayment * 0.3; 
	//$RS = $totalPayment * 0.03; 
	$webPage->addContent("<form name='listIONBudgetForm' method='post'>");
	$webPage->addContent("<table align = 'center' border=1 name='listIONBudgetTable'>");
	$webPage->addContent("<tr>");
	$webPage->addContent("<tr></td><th align= left><b>SEMESTER TOTAL EXPENSE of ION DEPARTMENT (YTL)    </b></th><th>$EXPENSE</th>");
	$webPage->addContent("<tr></td><th align= left><b>SEMESTER TOTAL INCOME of ION DEPARTMENT (YTL)       </b></th><th>$INCOME</th>");
	$BACKUP = $INCOME - $EXPENSE;
	$webPage->addContent("<tr></td><th align= left>BACKUP MONEY ( TOTAL INCOME - TOTAL EXPENSE) (YTL)       </th><th>$BACKUP</th>");
	//echo "dep[loopNo]: ";
	//echo "$dep[$loopNo]";	
	
	$webPage->addContent("</table>");
	$webPage->addContent("<table align = 'center'><tr>");
	$webPage->addContent("<td>");
	$webPage->addContent("</td>");
	$webPage->addContent("<td>");
	$webPage->addContent("</td>");
	$webPage->addContent("</tr></table></form>");	
}

//BURASI SAYFANIN BASLIGININ VE FOOTER'ININ OLUSTURULDUGU YER

$webPage = new Page();


//addJavaScripts($webPage);
$webPage->addHeader('INFORMATICS ONLINE BUDGET DETAILS FORM');
$webPage->addCenterContent("SEMESTER INCOME");



//$lc = $dcount + 1;
//echo "en alttaki lc: ";
//echo "$lc";
	
listIONBudgetForm($webPage);

	//$dc = $dcount + 1;
/*	echo "en alttaki dcount: ";
	echo "$dc";
	echo "<br>";
	echo $bosrow;
*/

listIONBudgetIncome($webPage);		
$webPage->addCenterContent("SEMESTER EXPENSE");
listIONBudgetExpense($webPage);	
$webPage->addCenterContent("SEMESTER BUDGET INCOME DETAILS");	
listIONBudgetDetails($webPage);
//-----------------------------------------------------
$webPage->addCenterContent("INCOMES FROM OTHER PROGRAMS");

$dc2 = $dcount2;

 if($dc2 == 0){
      $webPage->addCenterContent("!!! THERE ISN'T ANY INCOME FROM OTHER DEPARTMENTS !!!");
    }else{
  for($j2 = 0; $j2 < $dc2; $j2++){
      //echo "j: "."$j";
      $webPage->addCenterContent("Income from $depN2[$j2] Department");
      listNonIONStudents($webPage,$j2);		
      }
    }
    
$webPage->addCenterContent("SEMESTER BUDGET EXPENSE DETAILS");	    
listIONExpenseBudgetDetails($webPage);    
//-----------------------------------------------------
$webPage->addCenterContent("PAYMENTS TO THE OTHER PROGRAMS");

$dc = $dcount;

if($dc == 0){
      $webPage->addCenterContent("!!! THERE ISN'T ANY PAYMENT TO the OTHER PROGRAMS !!!");
    }else{
  for($j = 0; $j < $dc; $j++){
      //echo "dc: "."$dc"."<br>";
      
      
      //-----------------------------------------------
      
      //--------------ASAMA 1-----------------
      $result = DBConnectionManager::query("SELECT longName
      FROM program
      WHERE programCode = '$depNo[$j]'
      ");
      
      //--------------ASAMA 2-----------------
      $row = mysql_fetch_assoc($result);
      $programLongName = $row['longName'];
      //-----------------------------------------------
      
      
      $webPage->addCenterContent("Payments to $programLongName Department");
      listIONStudents($webPage,$j);		
      }
    }
$webPage->addCenterContent(":::::SEMESTER BUDGET TOTALS:::::");	    
listIONBudgetTotals($webPage);      
    
$webPage->addFooter(date('Y'), 'IIPIS');
echo $webPage->get();
include 'bottom.php';
?>